<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <base th:href="@{/}">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>修改密码</title>

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/bootstrap.min.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/fonts/line-icons.css}">

    <link rel="stylesheet" th:href="@{/assets/plugins/morris/morris.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/main.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/responsive.css}">

    <link rel="stylesheet" th:href="@{https://use.fontawesome.com/releases/v5.5.0/css/all.css}" crossorigin="anonymous">

    <script th:src="@{/assets/js/jquery-min.js}"></script>
    <script>
        function updatePwCheck(){
            var oldPwTiShi = $("#oldPwTiShi");

            var reg = /^.{6,}$/;
            var newPw = $("#newPw").val();
            var newPwTiShi = $("#newPwTiShi");
            if(!reg.test(newPw)){
                newPwTiShi.show();
                newPwTiShi.html("密码至少六位");
                return false;
            }else{
                newPwTiShi.hide();
            }
            var surePw = $("#surePw").val();
            var surePwTiShi = $("#surePwTiShi");
            if(newPw != surePw){
                surePwTiShi.show();
                surePwTiShi.html("两次密码输入不一样");
                return false;
            }else {
                surePwTiShi.hide();
            }

            var n = false;//全局变量，以便下面做判断

            $.ajax({
                async:false,//同步加载
                url:"/admin/user/updatePwCheck",
                dataType:"json",
                type:"post",
                data:{"id":$("#id").val(),
                    "passwd":$("#oldPw").val(),
                },
                success:function(data){
                    if(data.pwCheck == "false"){
                        oldPwTiShi.show();
                        oldPwTiShi.html(data.pwMessage);
                    } else {
                        n= true;
                    }
                },
                error:function(){
                    alert("运行异常");
                }
            });
            //全局判断
            if(n) {
                return true;
            }else{
                return false;
            }
        }

    </script>
</head>
<body>
<div class="app header-default side-nav-dark">
    <div class="layout">

        <div class="page-container pl-0">

            <div class="main-content">
                <div class="container-fluid">
                    <div class="card">
                        <div class="card-header border-bottom">
                            <h4 class="card-title">用户信息</h4>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-10 col-md-12 col-xs-12">
                                    <form action="/admin/user/sureUpdatePw" role="form" id="form-validation" novalidate="novalidate" th:object="${userEntity}" method="post" onsubmit="return updatePwCheck()">
                                        <div hidden="hidden">
                                            <input type="text" hidden="hidden" name="id" th:value="${userEntity.id}" id="id">
                                        </div>

                                        <div class="form-group row" id="userNameBigDiv">
                                            <label class="col-sm-2 col-form-label control-label">
                                              <span>旧密码</span>
                                            </label>
                                            <div class="col-sm-10">
                                                <div>
                                                    <input type="password" class="form-control" name="passwd" placeholder="用户旧密码" id="oldPw">
                                                </div>
                                                <p style="right: -98px;top: 10px;width: 100px;color: red;font-size: 0.68rem;" class="position-absolute" id="oldPwTiShi"></p>
                                            </div>
                                        </div>

                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label control-label">
                                               <span>新密码</span>
                                            </label>
                                            <div class="col-sm-10">
                                                <div>
                                                    <input type="password" class="form-control" name="newPw" placeholder="用户新密码" id="newPw">
                                                </div>
                                                <p style="right: -98px;top: 10px;width: 100px;color: red;font-size: 0.68rem;" class="position-absolute" id="newPwTiShi"></p>
                                            </div>
                                        </div>

                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label control-label">
                                                <span>确认密码</span>
                                            </label>
                                            <div class="col-sm-10">
                                                <div>
                                                    <input type="password" class="form-control" name="surePw" placeholder="确认新密码" id="surePw">
                                                </div>
                                                <p style="right: -98px;top: 10px;width: 100px;color: red;font-size: 0.68rem;" class="position-absolute" id="surePwTiShi"></p>
                                            </div>
                                        </div>



                                        <button class="btn btn-outline-success">
                                            <span>确认修改</span>
                                        </button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<div id="preloader">
    <div class="loader" id="loader-1"></div>
</div>

<script th:src="@{/assets/js/popper.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
<script th:src="@{/assets/js/jquery.app.js}"></script>
<script th:src="@{/assets/js/main.js}"></script>

<script th:src="@{/assets/plugins/morris/morris.min.js}"></script>
<script th:src="@{/assets/plugins/raphael/raphael-min.js}"></script>
<!--<script th:src="@{/assets/js/dashborad1.js}"></script>-->

<script th:src="@{https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js}" crossorigin="anonymous"></script>

</body>

</html>